﻿using System.Collections.Generic;
using System.Linq;

namespace HappyBa.Core.Validators
{
    class ValidationFacade : IValidationFacade
    {
        private readonly IList<IValidator> validators;
        public ValidationFacade (IList<IValidator> validators)
        {
            this.validators = validators;
        }

        public IList<ValidationResult> Validate(ValidationContext context)
        {
            return validators.SelectMany(x => Validate(context, x)).ToArray();
        }

        private static IEnumerable<ValidationResult> Validate(ValidationContext context, IValidator x)
        {
            var items = x.Validate(context).ToArray();
            foreach (var result in items)
            {
                result.ValidatorName = x.GetType().Name;
            }
            return items;
        }
    }
}
